package tp3.pages.java;

import java.util.List;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.CompoundPropertyModel;

import tp1.Casillero;
import tp1.Esfera;
import tp1.Personaje;
import tp1.Renglon;
import tp1_Model.Mapa;

public class DetalleTablero extends GeneralPage {
	private Component panelResultado;
	private static Mapa mapa;

	@SuppressWarnings({ "rawtypes", "rawtypes" })
	public DetalleTablero() {
		Form<Mapa> form = new Form<Mapa>("mapa", this.createModel());
		this.add(form);

		List<Renglon> renglones = Mapa.getInstance().getRenglones();
		ListView<Renglon> listViewRenglones = new ListView<Renglon>("listViewRenglon", renglones) {
			@Override
			protected void populateItem(ListItem<Renglon> item) {
				final Renglon renglon = item.getModelObject();
				ListView<Casillero> listview = new ListView<Casillero>("listView", renglon.getCasilleros()) {
					@Override
					protected void populateItem(ListItem<Casillero> item) {
						final Casillero cas = item.getModelObject();
						item.add(new Image("imagen", cas.getObjetoDragonBall()));
					}
				};
				item.add(listview);
			}
		};
		add(listViewRenglones);
		form.add(new DropDownChoice<Personaje>("personaje", Mapa.getInstance().getPersonajes()));
		form.add(new DropDownChoice<Esfera>("esfera", Mapa.getInstance().getEsferas()));
		Button irAesfera = new Button("iraesfera") {
			/**
			 *
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void onSubmit() {
				Mapa.getInstance().agregarEsferaAPersonaje();

			}
		};
		form.add(irAesfera);
	}

	protected CompoundPropertyModel<Mapa> createModel() {
		return new CompoundPropertyModel<Mapa>(Mapa.getInstance());
	}
}
